$('#btnManage').click(function() {
    var status = ($(this).text() === 'Stop') ? false : true;
    if (status) { //start app
        updateStatus(true);
    } else { //stop app
        updateStatus(false);
    }
});
function listSelected(page) {
    if (page === "") {
        page = 1;
    }
    $("#pn").val(page);
    $.ajax({
        url: 'export.php',
        data: {
            type: 'settled',
            pn: page,
        },
        beforeSend: function() {
            $('.settingRow.processing').show();
        },
        complete: function() {
            $('.settingRow.processing').hide();
        },
        success: function(result) {
            var obj = jQuery.parseJSON(result);
            // alert(result);
            if (obj.status === "success") {
                // request success
                // set page count and paging
                var pagingLink = "";
                if (obj.paging.totalCount > 0) {
                    // set paging count
                    $("#pagingCount").html(obj.paging.totalCountDisplay);
                    // set paging link
                    if (obj.paging.first !== "") {
                        pagingLink += obj.paging.firstLink;
                    }
                    if (obj.paging.preview !== "") {
                        pagingLink += obj.paging.previewLink;
                    }
                    $.each(obj.paging.onclickFunctionList, function(key, value) {
                        if (value === page)
                            pagingLink += "&nbsp";
                        pagingLink += value;// + "&nbsp";

                    });
                    if (obj.paging.next !== "") {
                        pagingLink += obj.paging.nextLink;
                    }
                    if (obj.paging.last !== "") {
                        pagingLink += obj.paging.lastLink;
                    }
                } else {
                    // no data
                }

                $("#pagingLink").html(pagingLink);
                $("#tableBody").html("");
                var runningCount = 0;

                var trData = "";
                // loop data , value is one user
                $.each(obj.data, function(key, value) {
                    var rowCss = '';
                    var rowStatus = '';
                    if (value.bet_slip === 'TEST_MODE') {
                        rowCss = ' test_mode';
                    }

                    if (value.running === '1') {
                        rowStatus = (value.dangerous === '1') ? 'rfire' : 'rball';
                        runningCount++;
                    } else {
                        rowStatus = (value.won === '1') ? 'victory' : 'failed';
                        if (value.dangerous === '1') {
                            rowStatus += ' fire';
                        }
                    }
                    trData = "<tr class='" + rowCss + "'>";
                    trData += '<input type="hidden" name="id_' + value.id + '"/>';
                    trData += '<input type="hidden" name="contractid_' + value.contract_id + ' "/>';
                    trData += '<td>' + value.country_name + '<br/>' + value.league_name + '</td>';
                    trData += '<td>' + value.home_name + '</td>';
                    trData += '<td>' + value.away_name + '</td>';
                    trData += '<td>' + value.current_time + '</td>';
                    trData += '<td>' + value.current_goal + '</td>';
                    trData += '<td>' + value.under_goal + '</td>';
                    trData += '<td>' + value.bet_amount + '</td>';
                    trData += '<td>' + value.rate + '</td>';
                    trData += '<td class="status ' + rowStatus + '">' + value.won + '</td>';
                    trData += '<td class="bet_slip" style="display: table-cell;">' + value.settled_total_goals + '</td>';
                    trData += '<td class="bet_slip" style="display: table-cell;">' + value.settled_play_time + '</td>';
                    trData += '<td class="bet_slip" style="display: table-cell;">' + value.won_amount + '</td>';
                    trData += '<td class="bet_slip" style="display: table-cell;">' + value.modify_timestamp + '</td>';
                    trData += '<td class="bet_slip" style="display: table-cell;">' + value.bet_slip + '</td>';
                    trData += "</tr>";
                    $("#tableBody").html($("#tableBody").html() + trData);
                });

            }
        }
    });
}
function autoReloadTable() {
    setTimeout(function(){alert("Hello")}, 3000);
}